package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.vo.WebsiteVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Website;
import com.ruoyi.system.service.IWebsiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网址导航Controller
 * 
 * @author 何文财
 * @date 2021-09-14
 */
@RestController
@RequestMapping("/system/website")
public class WebsiteController extends BaseController
{
    @Autowired
    private IWebsiteService websiteService;

    /**
     * 查询网址导航列表
     */
    @PreAuthorize("@ss.hasPermi('system:website:list')")
    @GetMapping("/list")
    public TableDataInfo list(Website website)
    {
        startPage();
        List<Website> list = websiteService.selectWebsiteList(website);
        return getDataTable(list);
    }


    /**
     * 查询网址导航列表(分页)
     */
    @PreAuthorize("@ss.hasPermi('system:website:list')")
    @GetMapping("/listByGroupName")
    public TableDataInfo listByGroupName(String groupName)
    {
        startPage();
        List<Website> list = websiteService.listByGroupName(groupName);
        return getDataTable(list);
    }




    /**
     * 查询网址导航列表（分组）
     */
    @PreAuthorize("@ss.hasPermi('system:website:list')")
    @GetMapping("/listGroupType")
    public AjaxResult listGroupType()
    {
        Map<String,List<Website>> map = websiteService.listGroupType();
        return AjaxResult.success(map);
    }


    /**
     * 导出网址导航列表
     */
    @PreAuthorize("@ss.hasPermi('system:website:export')")
    @Log(title = "网址导航", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Website website)
    {
        List<Website> list = websiteService.selectWebsiteList(website);
        ExcelUtil<Website> util = new ExcelUtil<Website>(Website.class);
        return util.exportExcel(list, "网址导航数据");
    }

    /**
     * 获取网址导航详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:website:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(websiteService.selectWebsiteById(id));
    }

    /**
     * 新增网址导航
     */
    @PreAuthorize("@ss.hasPermi('system:website:add')")
    @Log(title = "网址导航", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Website website)
    {
        return toAjax(websiteService.insertWebsite(website));
    }


    /**
     * 新增网址导航（同时更新网址舆情组）
     */
    @PreAuthorize("@ss.hasPermi('system:website:add')")
    @Log(title = "网址导航", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addWebsiteType")
    public AjaxResult addWebsiteType(@RequestBody WebsiteVo website)
    {
        return toAjax(websiteService.insertWebsite(website));
    }

    /**
     * 修改网址导航
     */
    @PreAuthorize("@ss.hasPermi('system:website:edit')")
    @Log(title = "网址导航", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Website website)
    {
        return toAjax(websiteService.updateWebsite(website));
    }

    /**
     * 删除网址导航
     */
    @PreAuthorize("@ss.hasPermi('system:website:remove')")
    @Log(title = "网址导航", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(websiteService.deleteWebsiteByIds(ids));
    }
}
